﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
using Telerik.UI.Xaml.Controls.Grid;
using System.Windows.Input;

namespace CityDashboard.Views
{
    public sealed partial class OverviewDataTableSection : UserControl
    {
        public ICommand RowClickCommand
        {
            get { return (ICommand)GetValue(RowClickCommandProperty); }
            set { SetValue(RowClickCommandProperty, value); }
        }

        // Using a DependencyProperty as the backing store for RowClickCommand.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RowClickCommandProperty =
            DependencyProperty.Register("RowClickCommand", typeof(ICommand), typeof(OverviewDataTableSection), new PropertyMetadata(null));


        public OverviewDataTableSection()
        {
            this.InitializeComponent();
        }

        private async void RadDataGrid_SelectionChanged(object sender,
            DataGridSelectionChangedEventArgs e)
        {
            var grid = sender as RadDataGrid;
            if (RowClickCommand != null)
                RowClickCommand.Execute(grid.SelectedItem);

            await Task.Delay(200);
            this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (grid.SelectedItem != null)
                {
                    grid.DeselectAll();
                }
            });

            

        }

    }
}
